﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace guest_management_in_a_hotel
{
    public partial class FrmThongTinPhong : Form
    {
        SqlConnection conn;
        SqlCommand cmd;
        SqlDataReader rd;
      
        public FrmThongTinPhong()
        {
            InitializeComponent();
        }

        private void FrmThongTinPhong_Load(object sender, EventArgs e)
        {
           // int soCMND =Int32.Parse(FrmQuanLyKhachHang.CMND);
           // lbso.Text = soCMND.ToString();
            conn = Connect.getConnection();
            try
            {
                conn.Open();
                String strsql = "select TblGuests.Guest_Passport_No,TblGuests.Guest_Name,TblGuests.Guest_Sex,TblGuests.Guest_DOB,TblGuests.Guest_Address,TblGuests.Guest_Nationality,TblReserve.Room_Number,TblReserve.Reserve_Date,TblReserve.Arrival_Date,TblReserve.Due_Date from TblGuests,TblReserve where TblReserve.Guest_Passport_No='" + FrmQuanLyKhachHang.CMND + "' and TblGuests.Guest_Passport_No=TblReserve.Guest_Passport_No";

                
                cmd = new SqlCommand(strsql, conn);


                rd = cmd.ExecuteReader();
                if (rd.Read())
                {
                    lbcmnd.Text = rd.GetInt32(0).ToString();
                    lbhoten.Text = rd.GetString(1);
                    lbgioitinh.Text = rd.GetString(2);
                    lbngaysinh.Text = rd.GetDateTime(3).ToShortDateString();
                    lbdiachia.Text = rd.GetString(4);
                    lbquoctich.Text = rd.GetString(5);
                    lbphongso.Text = rd.GetInt32(6).ToString();
                    lbngaythue.Text = rd.GetDateTime(7).ToShortDateString();
                    lbngayden.Text = rd.GetDateTime(8).ToShortDateString();
                    lbngaytra.Text = rd.GetDateTime(9).ToShortDateString();
                }
            }
            catch (SqlException ex) {
                MessageBox.Show(ex.Message);
            }
                    conn.Close();
            
               
        }

        private void button1_Click(object sender, EventArgs e)
        {
            conn = Connect.getConnection();
            try
            {
                conn.Open();
                String strsql = "delete from TblReserve where TblReserve.Guest_Passport_No='" + FrmQuanLyKhachHang.CMND + "'";
                cmd = new SqlCommand(strsql, conn);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Trả phòng thành công!", "Thông báo");

                FrmMain frmMain = new FrmMain();
                frmMain.Show();
                this.Hide();
            }
            catch (SqlException ex1) {
                MessageBox.Show(ex1.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FrmQuanLyKhachHang frmquanlykhachhang = new FrmQuanLyKhachHang();
            frmquanlykhachhang.Show();
            this.Hide();
        }
    }
}
